var express = require('express'); //引入框架
var db = require('./db.js')
var route = express.Router();

var bodyParser = require('body-parser');
var urlencodedParser = bodyParser.urlencoded({
    extended: false
})
var https = require('https')

route.get('/wx-login',function(req,res){
    const {code} = req.query
	// console.log(code)
	//赵
	// let url = 'https://api.weixin.qq.com/sns/jscode2session?appid=wx0bfb8bdf0873bf4d&secret=28c1dba0181a942b4cf1ed727757485e&js_code='+code+'&grant_type=authorization_code'
	//王
	let url = 'https://api.weixin.qq.com/sns/jscode2session?appid=wx799eba37d47caf88&secret=5a9ca5db1097f0cfc4c5d7ad3cac844f&js_code='+code+'&grant_type=authorization_code'
	let r = https.request(url,function(res2){
		res2.setEncoding('utf-8');
		res2.on('data',function(chunk){
			var data = JSON.parse(chunk);
            // console.log(data)
            res.send(data)
		})
	})
	// res.send(data)
	r.end()
})

exports.route = route